﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Mesuro.GUI {
	public class ResizableCanvas : Canvas {
		protected override System.Windows.Size MeasureOverride( System.Windows.Size constraint ) {
			double w = 0, h = 0;
			foreach (FrameworkElement child in InternalChildren) {
				base.MeasureOverride( constraint );

				foreach (UIElement i in InternalChildren.OfType<UIElement>()) {
					w = Math.Max( w, i.DesiredSize.Width + (double)i.GetValue( Canvas.LeftProperty ) );
					h = Math.Max( h, i.DesiredSize.Height + (double)i.GetValue( Canvas.TopProperty ) );
				}
			}
			return new Size( w, h );
		}
	}
}
